package com.springapp.mvc.tools;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class ZipDecompressing {

    public static void decompression(InputStream is, String path, String fileName) {
        try {
            ZipInputStream Zin = new ZipInputStream(is);
            BufferedInputStream Bin = new BufferedInputStream(Zin);
            File Fout = null;
            ZipEntry entry;
            while ((entry = Zin.getNextEntry()) != null && !entry.isDirectory()) {
                Fout = new File(path, fileName);
                if (!Fout.exists()) {
                    (new File(Fout.getParent())).mkdirs();
                }
                FileOutputStream out = new FileOutputStream(Fout);
                BufferedOutputStream Bout = new BufferedOutputStream(out);
                int b;
                while ((b = Bin.read()) != -1) {
                    Bout.write(b);
                }
                Bout.close();
                out.close();
            }
            Bin.close();
            Zin.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}